// CanvasWnd.h: interface for the CCanvasWnd class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_CANVASWND_H__FE86E9B1_39A8_4BB2_B96B_2A9BDFF704E7__INCLUDED_)
#define AFX_CANVASWND_H__FE86E9B1_39A8_4BB2_B96B_2A9BDFF704E7__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "SimpleWnd/SimpleWnd.h"
#include "ExecStub.h"
#include "ICanvas.h"
#include "CanvasDoc.h"
#include "TurtleWnd.h"
#include "Commander.h"

#define CANVAS_WINDOW_CLASS "TROPHY_LOGO_CANVAS_WINDOW"

class ICanvasContainer;

class CCanvasWnd : public CWnd,
    public ICanvas  
{
public:
    DECLARE_WND_CLASS_EX(CANVAS_WINDOW_CLASS, 0, NO_BACKGROUND)

    CCanvasWnd();
	 virtual ~CCanvasWnd();

    void SetContainer(ICanvasContainer* ctn);
    void SetExecCommander (IExecCommander* cmd);

BEGIN_MSG_MAP(CCanvasWnd)
    MESSAGE_HANDLER(WM_CREATE, OnCreate)
    MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
    MESSAGE_HANDLER(WM_SIZE, OnSize)
    MESSAGE_HANDLER(WM_MOVE, OnMove)
    MESSAGE_HANDLER(WM_PAINT, OnPaint)
    MESSAGE_HANDLER(WM_TIMER, OnTimer)
    MESSAGE_HANDLER(MSG_EX_CS, OnCs)
    MESSAGE_HANDLER(MSG_EX_RESET, OnReset)
    MESSAGE_HANDLER(MSG_EX_CLEAR, OnClear)
    MESSAGE_HANDLER(MSG_EX_HIDE, OnHide)
    MESSAGE_HANDLER(MSG_EX_CC, OnCc)
    MESSAGE_HANDLER(MSG_EX_PC, OnPc)
    MESSAGE_HANDLER(MSG_EX_PW, OnPw)
    MESSAGE_HANDLER(MSG_EX_GO, OnGo)
    MESSAGE_HANDLER(MSG_EX_DIR, OnDir)
    MESSAGE_HANDLER(MSG_EX_TR, OnTr)
    MESSAGE_HANDLER(MSG_EX_TL, OnTl)
    MESSAGE_HANDLER(MSG_EX_FW, OnFw)
    MESSAGE_HANDLER(MSG_EX_BW, OnBw)
    MESSAGE_HANDLER(MSG_EX_FONTSIZE, OnFontsize)
    MESSAGE_HANDLER(MSG_EX_PRINT, OnPrint)
    MESSAGE_HANDLER(MSG_EX_PU, OnPu)
    MESSAGE_HANDLER(MSG_EX_PD, OnPd)
    MESSAGE_HANDLER(MSG_EX_CENTER, OnCenter)
    MESSAGE_HANDLER(MSG_EX_GOX, OnGox)
    MESSAGE_HANDLER(MSG_EX_GOY, OnGoy)
    MESSAGE_HANDLER(MSG_EX_WRAPON, OnWrapOn)
    MESSAGE_HANDLER(MSG_EX_WRAPOFF, OnWrapOff)
    MESSAGE_HANDLER(MSG_EX_SHOW, OnShow)
    MESSAGE_HANDLER(MSG_EX_INPUT, OnInput)
    MESSAGE_HANDLER(MSG_EX_MSG, OnMsg)
    MESSAGE_HANDLER(MSG_EX_DBGINFO, OnDbgInfo)
    MESSAGE_HANDLER(MSG_EX_ERRINFO, OnErrorInfo)
    MESSAGE_HANDLER(MSG_EX_DONE, OnDone)
    MESSAGE_HANDLER(MSG_DEBUG_ACK, OnDebugAck)
END_MSG_MAP()

public: /* ICanvas */
    virtual int GetTextRect(const Text& txt, RECT& rc);
    virtual void DrawStroke(CStroke* stk, HDC hdc=NULL);
	virtual	void DrawTurtle ();

protected:
    void DrawStkLine (HDC hdc, CStroke* stk);
    void DrawStkText (HDC hdc, CStroke* stk);

protected:
    LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnCs(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnReset(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnClear(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnHide(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnCc(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnPc(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnPw(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnGo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnDir(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnTr(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnTl(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnFw(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnBw(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnFontsize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnPrint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnPu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnPd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnCenter(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnGox(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnGoy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnWrapOn(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnWrapOff(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnShow(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnInput(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnMsg(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnDbgInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnErrorInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnDone(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnDebugAck(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

    void SetDelayTimer(DWORD thread);    

public:
    void SetErrorInfoWindow(HWND hErrWnd);
    void SetDelay(WORD ms) {m_delay = ms;};

    CCanvasDoc  m_doc;
    ICanvasContainer* m_container;
    IExecCommander* m_commander;


protected:
	CTurtleWnd m_wndTurtle;
   UINT m_delay;
   UINT m_uDelayTimer;
   DWORD m_uThread;
};

#endif // !defined(AFX_CANVASWND_H__FE86E9B1_39A8_4BB2_B96B_2A9BDFF704E7__INCLUDED_)
